package hu.uniobuda.nik.bsik2f.ListViewPelda;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created with IntelliJ IDEA.
 * User: Matusinka Roland
 * Date: 2013.03.25.
 * Time: 15:54
 */

public class SajatAdapter extends BaseAdapter {

    JSONArray array;

    public SajatAdapter(String uri) {
        try {
            URL url = new URL(uri);
            URLConnection connection = url.openConnection();

            StringBuilder sb = new StringBuilder();
            InputStream is = connection.getInputStream();

            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            String line;

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getCount() {
        return array.length();
    }

    @Override
    public Object getItem(int i) {
        try {
            return array.get(i);
        } catch (JSONException e) {
            return null;
        }
    }

    @Override
    public long getItemId(int i) {
        return 0;  // TODO
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view==null){
            view = View.inflate(viewGroup.getContext(),R.layout.list_item,viewGroup);
        }

        TextView tvVaros = (TextView)view.findViewById(R.id.varos);
        TextView tvLakossag = (TextView)view.findViewById(R.id.lakossag);

        JSONArray positionArray

        return view;
    }
}
